{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e684b932",
   "metadata": {},
   "outputs": [],
   "source": [
    "import OperateCardLib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e239d31b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Read DPCD Data: 14 1E C4 C1 00 00 01 C0 02 00 02 00 08 09 84 00\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'DPCD v.': '1.4', 'Max Link Rate': '8.1Gbps/lane', 'Max Lane Count': '4-lane'}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Nova_NT71877(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        read_data = card_lib.read_dpcd(0x0000, 16)\n",
    "        print(\"Read DPCD Data:\", read_data.hex(\" \").upper())\n",
    "\n",
    "        display(card_lib.parse_dpcd(read_data))\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1bc55b4e",
   "metadata": {},
   "source": [
    "# 修改vcom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8c53a866",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Nova_NT71877(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        card_lib.write_vcom(0x41)\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "134d0078",
   "metadata": {},
   "source": [
    "# 修改PMIC AVDD AVEE\n",
    "### 用于NT50805 PMIC 16 3.2K联想"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a7a4e173",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Nova_NT71877(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        card_lib.iic_over_aux_write(0x46,0x03,[0x1F*2])\n",
    "        card_lib.iic_over_aux_write(0x46,0x04,[0x1F])\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9391df88",
   "metadata": {},
   "source": [
    "# VGH VGL"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "d7fbac0c",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import OperateCardLib\n",
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Nova_NT71877(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        card_lib.iic_over_aux_write(0x46,0x05,[0x14])\n",
    "        card_lib.iic_over_aux_write(0x46,0x06,[0x03])\n",
    "\n",
    "        # hr 0x87高压 0x7低压\n",
    "        # card_lib.iic_over_aux_write(0x46,0x01,[0x87])\n",
    "\n",
    "        #print(card_lib.iic_over_aux_read(0x46, 0x01, 1).hex())\n",
    "\n",
    "\n",
    "        # MTP\n",
    "        card_lib.iic_over_aux_write(0x46,0xFF,[0x80])\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e9ed1f14",
   "metadata": {},
   "source": [
    "# 修改PMIC AVDD AVEE\n",
    "### 用于RT6755 PMIC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a15c98dd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "6ce08dd3",
   "metadata": {},
   "source": [
    "# 获取全体GAM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0cafac47",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.ANX_ANX2176(dll_path)\n",
    "        card_lib.init(6)\n",
    "\n",
    "        # TCON Can be accessed after writing password\n",
    "        card_lib.write_dpcd(0x004F5, b\"\\x41\\x56\\x4F\\x20\\x16\")\n",
    "        card_lib.write_dpcd(0x004F0, b\"\\x0E\\x00\\x00\\x00\")\n",
    "\n",
    "        card_lib.write_dpcd(0x004F3, b\"\\x01\")\n",
    "\n",
    "        # 0X69-0X7E对应P255 ... P0 N0 ...N0，共22个帮点,同一灰阶正负极性绑点间之和=255时，gamma对称\n",
    "        gamma_list = []\n",
    "        for i in range(0x69, 0x7E+1,1):\n",
    "            card_lib.write_dpcd(0x004F0, b\"\\x0A\\x00\\x00\"+ bytes([i]))\n",
    "            gamma_list.append(card_lib.read_dpcd(0x004F4, 1))\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "\n",
    "        print(\"gray: \",[\"L255+\",\"L254+\",\"L247+\",\"l224+\",\"L192+\",\"L128+\",\"L64+\",\"L32+\",\"L7+\",\"L1+\",\"L0+\",\"L0-\",\"L1-\",\"...\"])\n",
    "        print(\"reg: \",[hex(i)[2:] for i in range(0x69, 0x7E+1,1)])\n",
    "        print(\"val: \",[i.hex() for i in gamma_list])\n",
    "\n",
    "    finally:\n",
    "        del card_lib"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6118fb7",
   "metadata": {},
   "source": [
    "# 修改Gama L0值为0xFF"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d7d2dffd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Nova_NT71877(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        card_lib.change_gamma(0xD8,0xFF)\n",
    "        card_lib.change_gamma(0xD9,0xFF)\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e37c360f",
   "metadata": {},
   "source": [
    "# TCON read"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "89210690",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0x57\n"
     ]
    }
   ],
   "source": [
    "import OperateCardLib\n",
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Nova_NT71877(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        # TCON Reg地址 7bit地址0x61  8bit 0xC2\n",
    "        print(card_lib.read_tcon_reg(0x34,0x80))\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5dec1a7",
   "metadata": {},
   "source": [
    "# PSR\n",
    "地址使用0xC0问题，这里用C2启动PSR无效"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "be1e25d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import OperateCardLib\n",
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Nova_NT71877(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        # 启动PSR\n",
    "        card_lib.write_tcon_reg(0X83, 0X7f, 0X01)\n",
    "        # 关闭PSR\n",
    "        #card_lib.write_tcon_reg(0X83, 0X7f, 0X00)\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9878a912",
   "metadata": {},
   "source": [
    "# B802电流调整"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f4585ba8",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import OperateCardLib\n",
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Nova_NT71877(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        #card_lib.iic_over_aux_write(0x6c,0x18,[0x1])\n",
    "        card_lib.iic_over_aux_write(0x6E,0x01,[0x01])\n",
    "\n",
    "        # hr 0x87高压 0x7低压\n",
    "        # card_lib.iic_over_aux_write(0x46,0x01,[0x87])\n",
    "\n",
    "        #print(card_lib.iic_over_aux_read(0x46, 0x01, 1).hex())\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0cdd01ee",
   "metadata": {},
   "source": [
    "# 背光控制\n",
    "基于DPCD实现背光控制，未实现TODO"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ca9d2ee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0x00721h: 00001000\n",
      "0x00702h: 10000111\n",
      "0x00722h: 00000000\n",
      "0x00723h: 11111111\n"
     ]
    }
   ],
   "source": [
    "\n",
    "import OperateCardLib\n",
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Nova_NT71877(dll_path)\n",
    "        card_lib.init(6)\n",
    "\n",
    "        read_data = card_lib.read_dpcd(0x0721, 1)\n",
    "        print(\"0x00721h:\", ''.join(format(byte, '08b') for byte in read_data))\n",
    "\n",
    "        read_data = card_lib.read_dpcd(0x0702, 1)\n",
    "        print(\"0x00702h:\", ''.join(format(byte, '08b') for byte in read_data))\n",
    "\n",
    "        read_data = card_lib.read_dpcd(0x0722, 1)\n",
    "        print(\"0x00722h:\", ''.join(format(byte, '08b') for byte in read_data))\n",
    "\n",
    "        read_data = card_lib.read_dpcd(0x0723, 1)\n",
    "        print(\"0x00723h:\", ''.join(format(byte, '08b') for byte in read_data))\n",
    "\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b4c49487",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0x00723h: 00000000\n"
     ]
    }
   ],
   "source": [
    "\n",
    "import OperateCardLib\n",
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Nova_NT71877(dll_path)\n",
    "        card_lib.init(6)\n",
    "\n",
    "        card_lib.write_dpcd(0x0722, b'\\xff')\n",
    "\n",
    "        read_data = card_lib.read_dpcd(0x0722, 1)\n",
    "        print(\"0x00723h:\", ''.join(format(byte, '08b') for byte in read_data))\n",
    "\n",
    "\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "055ebea3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
